package cn.safeness.repo;

import cn.safeness.entity.system.account.ManagerEntity;
import cn.safeness.entity.system.account.RoleEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

@Mapper
public interface AccountRepo {

    @Select("show tables")
    List<String> showTables();

    @Select("SELECT * FROM manager WHERE manager_name = #{name}")
    @Results({
            @Result(property = "id", column = "manager_id"),
            @Result(property = "name", column = "manager_name"),
            @Result(property = "password", column = "manager_password"),
            @Result(property = "tel", column = "manager_tel"),
            @Result(property = "email", column = "manager_email")
    })
    ManagerEntity selectAccountByName(String name);

    @Select("SELECT * FROM role WHERE role_id IN (SELECT role_id FROM manager_role WHERE manager_id = #{id})")
    @Results({
            @Result(property = "id", column = "role_id"),
            @Result(property = "name", column = "role_name"),
            @Result(property = "type", column = "role_type"),
            @Result(property = "description", column = "role_description")
    })
    Set<RoleEntity> selectRoleById(int id);

}
